#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){

    // declaration container and iterator
    map<string, string> mapStudent;
    map<string, string>::iterator iter;
    map<string, string>::reverse_iterator iter_r;

    // insert element
    // if insert the same key, can't replace this key homologous value;
    mapStudent.insert(pair<string, string>("r000", "student_zero"));
    mapStudent.insert(map<string, string>::value_type("r777", "smitish"));
    mapStudent["r123"] = "student_first";
    mapStudent["r456"] = "student_second";

    // traversal
    cout << "for iterator traversal" << endl;
    for (iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
        cout << "k:" << iter->first << " v:" << iter->second << endl;
    
    cout << "for reverse_iterator traversal" << endl;
    for (iter_r = mapStudent.rbegin(); iter_r != mapStudent.rend(); iter_r++)
        cout << "k:" << iter_r->first << " v:" << iter_r->second << endl;

    // find and erase the element
    iter = mapStudent.find("r123");
    mapStudent.erase(iter);

    iter = mapStudent.find("r123");
    cout << mapStudent.max_size() << endl;
    if (iter != mapStudent.end())
        cout << "Find, the value is " << iter->second << endl;
    else
        cout << "Do not Find" << endl; 

    return 0;
}